//
// Created by zhulingfeng on 2020/2/27.
//

#ifndef SORTING_SRC_LIST_NODE_HPP_
#define SORTING_SRC_LIST_NODE_HPP_
#include <ostream>
class ListNode {
 public:
  int val;
  ListNode* next;
  ListNode() : ListNode(0) {}
  explicit ListNode(int v) : val(v), next(nullptr) {}
  void Insert(int v) {
    auto temp = this->next;
    this->next = new ListNode(v);
    this->next->next = temp;
  }
  void DeleteList() {
    while (this->next) {
      auto temp = this->next->next;
      delete this->next;
      this->next = temp;
    }
  }
  friend std::ostream& operator<<(std::ostream& os, const ListNode& dummy) {
    auto head = dummy.next;
    os << "{";
    while (head) {
      os << head->val << ",";
      head = head->next;
    }
    os << "}";
    return os;
  }
};
inline bool operator==(const ListNode& dummy1, const ListNode& dummy2) {
  auto head1 = dummy1.next;
  auto head2 = dummy2.next;
  while (head1 && head2) {
    if (head1->val != head2->val) return false;
    head1 = head1->next;
    head2 = head2->next;
  }
  return !(head1 || head2);
}
inline bool operator!=(const ListNode& dummy1, const ListNode& dummy2) {
  return !(dummy1 == dummy2);
}

#endif  // SORTING_SRC_LIST_NODE_HPP_
